package cn.rkylin.oms.sysOrder.dao.impl;

import cn.rkylin.core.IDataBaseFactory;
import cn.rkylin.oms.sysOrder.dao.ISysOrderDAO;
import cn.rkylin.oms.sysOrder.domain.SysOrder;
import cn.rkylin.oms.sysOrder.domain.SysOrderGoods;
import cn.rkylin.oms.sysOrder.vo.SysOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * 类名:SysOrderDAOImpl <br/>
 * 作用: 系统订单数据访问层实现. <br/>
 * 创建原因: 系统订单数据访问层实现. <br/>
 * 创建时间: 2017年9月22日 下午2:51:47 <br/>
 *
 * @author zhanghao
 * @version v1.0
 */
@Repository
public class SysOrderDAOImpl implements ISysOrderDAO {
    @Autowired
    protected IDataBaseFactory dao;

    private String STATEMENT_QUERY_SYSORDER = "selectSysOrderByCondition";
    private String STATEMENT_QUERY_SYSORDERGOODS = "selectSysOrderGoodsInOrderSkuId";
    private String STATEMENT_QUERY_DELETED_SYSORDERGOODS = "selectDeletedSysOrderGoodsByOrderId";
    private String STATEMENT_QUERY_SYSORDERBYTRADECODE = "selectSysOrderInTradeCode";
    private String STATEMENT_QUERY_COMBSYSORDERBYTRADECODE = "selectCombSysOrderInTradeCode";
    private String UPDATE_SELECTIVE_ORDER_SKU = "updateByPrimaryKeySelectiveOrderSku";

    public SysOrderDAOImpl() {

    }

    /**
     * 获取系统的订单数据集通过多个平台交易号批量条件
     *
     * @param reqMap
     * @return
     * @throws Exception
     */
    public List<String> selectSysOrderListByTradeCode(Map<String, Object> reqMap) throws Exception {
        return dao.findForList(STATEMENT_QUERY_SYSORDERBYTRADECODE, reqMap);
    }

    /**
     * 系统订单主表信息插入数据库
     *
     * @param record
     * @return
     * @throws Exception
     */
    public int insertSelectiveSysOrder(SysOrder record) throws Exception {
        return dao.insert("insertSelectiveSysOrder", record);
    }

    /**
     * 系统订单商品明细信息插入数据库
     *
     * @param record
     * @return
     * @throws Exception
     */
    public int insertSelectiveSysOrderGoods(SysOrderGoods record) throws Exception {
        return dao.insert("insertSelectiveSysOrderGoods", record);
    }

    /**
     * 更新系统订单
     *
     * @param record
     * @return
     * @throws Exception
     */
    public int updateByPrimaryKeySelectiveSysOrder(SysOrderVO record) throws Exception {
        return dao.update("updateByPrimaryKeySelectiveSysOrder", record);
    }
    
    /**
     * 更新系统订单
     *
     * @param record
     * @return
     * @throws Exception
     */
    public int updateByPrimaryKeySelectiveOrderSku(Map<String, Object> reqMap) throws Exception {
        return dao.update(UPDATE_SELECTIVE_ORDER_SKU, reqMap);
    }

    /**
     * 获取系统的订单数据集
     *
     * @param reqMap
     * @return
     * @throws Exception
     */
    public List<SysOrderVO> selectSysOrderList(Map<String, String> reqMap) throws Exception {
        return dao.findForList(STATEMENT_QUERY_SYSORDER, reqMap);
    }

    /**
     * 获取系统订单商品明细数据集
     *
     * @param reqMap
     * @return
     * @throws Exception
     */
    public List<SysOrderGoods> selectSysOrderGoodsList(Map<String, Object> reqMap) throws Exception {
        return dao.findForList(STATEMENT_QUERY_SYSORDERGOODS, reqMap);
    }

    /**
     * 更新合并前系统订单合并状态
     *
     * @param map
     * @return
     * @throws Exception
     */
    public int updateBeforeSysOrderStatus(Map<String, Object> map) throws Exception {
        return dao.update("updateSysOrderInOrderId", map);
    }

    /**
     * 获取系统的合并订单数据集通过多个合并前的平台交易号批量条件
     *
     * @param reqMap
     * @return
     * @throws Exception
     */
    public List<SysOrderVO> selectCombSysOrderListByTradeCode(Map<String, Object> reqMap) throws Exception {
        return dao.findForList(STATEMENT_QUERY_COMBSYSORDERBYTRADECODE, reqMap);
    }

    /**
     * 更新系统订单完成状态
     *
     * @param record
     * @return
     * @throws Exception
     */
    public int updateSysOrderFinishStatus(SysOrderVO record) throws Exception {
        return dao.update("updateSysOrderFinishStatus", record);
    }

    /**
     * 更新系统订单商品明细
     *
     * @param record
     * @return
     * @throws Exception
     */
    public int updateByPrimaryKeySelectiveSysOrderGoods(SysOrderGoods record) throws Exception {
        return dao.update("updateByPrimaryKeySelectiveSysOrderGoods", record);
    }

    /**
     * 更新系统订单平台发货时间
     */
    @Override
    public int updateByTradeCodeSysOrderConsignTime(SysOrderVO record) throws Exception {
        return dao.update("updateByTradeCodeSysOrderConsignTime", record);
    }

    /**
     * 获取合并后已删除的系统退款单商品.
     * 
     * @throws Exception
     * @see cn.rkylin.oms.sysOrder.dao.ISysOrderDAO#selectDeletedSysOrderGoodsList(java.util.Map)
     */
    @Override
    public List<SysOrderGoods> selectDeletedSysOrderGoodsList(Map tempQueryMap) throws Exception {
        return dao.findForList(STATEMENT_QUERY_DELETED_SYSORDERGOODS, tempQueryMap);
    }

}
